package com.atzxh.collection.set;

import java.util.HashSet;
import java.util.Objects;

/**
 * @author 小红同学
 * @create 2022-10-15-9:35
 * @description
 */
@SuppressWarnings({"all"})
public class HashSet_Exer {
    public static void main(String[] args) {
        HashSet hashSet = new HashSet();

        hashSet.add(new Employee("jack",12,new MyDate("2000","2","2")));
        hashSet.add(new Employee("tom",12,new MyDate("1998","2","2")));
        hashSet.add(new Employee("jack",12,new MyDate("2000","2","2")));

        System.out.println(hashSet);

    }
}

class Employee{
    private String name;
    private int age;
    private MyDate birthday;

    public Employee(String name, int age, MyDate birthday) {
        this.name = name;
        this.age = age;
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", birthday=" + birthday +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employee employee = (Employee) o;
        return Objects.equals(name, employee.name) && Objects.equals(birthday, employee.birthday);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, birthday);
    }
}

class MyDate{
    private String year;
    private String mouth;
    private String day;

    public MyDate(String year, String mouth, String day) {
        this.year = year;
        this.mouth = mouth;
        this.day = day;
    }

    @Override
    public String toString() {
        return year + '-' + mouth + '-'+ day ;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MyDate myDate = (MyDate) o;
        return Objects.equals(year, myDate.year) && Objects.equals(mouth, myDate.mouth) && Objects.equals(day, myDate.day);
    }

    @Override
    public int hashCode() {
        return 0;
    }
}